#include <iostream>
#include <algorithm>
#include<vector>
#include <set>
#include <sstream>
#include <map>
#include <cstdio>
#include <ctime>
using namespace std;

bool cmp(int a, int b) {
	return a > b;
}

int main() {

	int a, b;
	vector<int> m, n;
	vector<double> t;

	clock_t start, finish;

	//scanf("%d", &a);

	for (b = 1000; b < 10000; b++) {
		a = b;
		printf("a = %dʱ------------------------------\n", a);
		m.clear();
		n.clear();
		start = clock();

		if (a % 1111 == 0) {
			printf("N - N = 0000\n");
			continue;
		}

		while (a != 0){
			m.push_back(a % 10);
			n.push_back(a % 10);
			a /= 10;
		}


		vector<int> temp;

		while (true) {
			temp.clear();
			sort(m.begin(), m.end(), cmp);
			for(int i = 0; i < m.size(); i++) {
				printf("%d", m[i]);
			}
			printf(" - ");
			sort(n.begin(), n.end());
			for(int i = 0; i < n.size(); i++) {
				printf("%d", n[i]);
			}
			printf(" = ");
		
			for(int i = 3; i >= 0; i--) {
				temp.clear();
				int tmp = m[i] - n[i];
				if (tmp >= 0) {
					temp.push_back(tmp);
					m[i] = tmp;
					n[i] = m[i];
				} else{
					temp.push_back(tmp + 10);
					m[i - 1]--;
					m[i] = tmp + 10;
					n[i] = m[i];
				}
			}
			for (int i = 0; i < 4; i++) {
				printf("%d", m[i]);
			}
			printf("\n");

			if (m[0] == 6 && m[1] == 1 && m[2] == 7 && m[3] == 4) {
				break;
			}

		}
		finish = clock();
		t.push_back((double)(finish - start) / CLOCKS_PER_SEC);
		//printf("time: %.2f\n", (double)(finish - start) / CLOCKS_PER_SEC);
		printf("--------------------------------\n");
	}

	for (auto it = t.begin(); it != t.end(); it++) {
		printf("%f\n", *it);
	}



    return 0;
}	